package com.netflexitysolutions.amazonws.ec2.internal.operations;

import java.util.ArrayList;

import com.amazonaws.ec2.doc._2009_04_04.CreateVolumeResponseType;
import com.amazonaws.ec2.doc._2009_04_04.CreateVolumeType;
import com.netflexitysolutions.amazonws.ec2.AttachmentInfo;
import com.netflexitysolutions.amazonws.ec2.EC2;
import com.netflexitysolutions.amazonws.ec2.Volume;
import com.netflexitysolutions.amazonws.ec2.internal.ModelUtil;

public class CreateVolumeOperation extends OperationExecutor<CreateVolumeType, Volume> {
	
	private String snapshotId;
	
	private String availabilityZone;
	
	private String size;
	
	public CreateVolumeOperation(EC2 ec2, String snapshotId, String size, String availabilityZone) {
		super(ec2);
		this.snapshotId = snapshotId;
		this.size = size;
		this.availabilityZone = availabilityZone;
	}

	@Override
	protected Volume call(CreateVolumeType request) {
		request.setAvailabilityZone(availabilityZone);
		request.setSize(size);
		request.setSnapshotId(snapshotId);
		CreateVolumeResponseType response = getEC2().getService().createVolume(request);
		Volume result = new Volume(response.getVolumeId(), response.getSize(), response.getSnapshotId(), 
				response.getAvailabilityZone(), response.getStatus(), ModelUtil.toDomainType(response.getCreateTime()),
				new ArrayList<AttachmentInfo>());
		return result;
	}
	
	
	
}
